I/O STREAMS : objects and manipulators, examples
_________________________________________________________________________

The standard input/output (I/O) library for C++ is <iostream.h>, not <stdio.h>.  Although C++ supports the "old" I/O functions, you should probably get use to using streams.  The following provides the basics of using C++ streams.

OBJECTS AND MANIPULATORS

                            C++ I/O OBJECTS
                 =====================================
                |  Object Name      Default Device    |
                |-------------------------------------|
                |     cin              Keyboard       |
                |     cout              Screen        |
                |     cerr              Screen        |
                |     clog              Screen        |
                 =====================================

                          C++ I/O MANIPULATORS
    ================================================================
   |  Manipulator                               Description         |
   |----------------------------------------------------------------|
   |     dec                          Decimal output                |
   |     hex                          Hexadecimal output            |          
   |     oct                          Octal output                  |
   |     endl                         End of line (or \n)           |
   |     ends                         End of string (or \0)         |
   |     flush                        Flushes buffer                |
   |     resetiosflags(long)          Resets effect of setiosflags  |
   |     setprecision( int )          Secifies digits of precision  |
   |     setiosflags( format flag )   Sets format flag              |
   |     setw( int )                  Sets field width              |
    ================================================================

                          C++ I/O FORMAT FLAGS
    ================================================================
   |  Format Flag                       Description                 |
   |----------------------------------------------------------------|
   |  ios::left          Left-justified output within width         |
   |  ios::right         Right-justified output within width        |
   |  ios::scientific    Formats numbers in scientific notation     |
   |  ios::fixed         Normal decimal format                      |
   |  ios::dec           Formats numbers in base 10                 |
   |  ios::hex           Formats numbers in base 16                 |
   |  ios::oct           Formats numbers in base 8                  |
   |  ios::uppercase     Scientific notation characters uppercase   |
   |  ios::showbase      Force base prefix in output                |
   |  ios::showpos       Show '+' sign for positive numbers         |
    ================================================================

EXAMPLES

The following snippet shows how to use the basics of using C++ I/O streams.  The insert operator '<<' and extraction operator '>>' are used to send and get data from the screen and keyboard.

  // io.cp
  #include <iostream.h>
  #include <iomanip.h>
    
  void main( void )
  
    int   i;
    float f;
    char  c;
    
    cout << "Enter an integer: ";
    cin >> i;
    cout << "Enter a float: ";
    cin >> f;
    cout << "Enter a character: ";
    cin >> c;
    
    cout << endl;
    cout << "Default formats" << endl;
    cout << i << endl;
    cout << f << endl;
    cout << c << endl;
    
    cout << endl << "Other formats" << endl;
    cout << hex << i << endl;
    cout << setprecision(2) << f << endl;
    cout << setiosflags( ios::scientific ) << f << endl;
  
  // end io.cp